using System.Collections.Generic;
using OpenViewer.Models;
using ThirdLife.Render.MogrePlugin.Common;

namespace ThirdLife.Render.MogrePlugin
{
  public delegate void AddTerrainHandler(Dictionary<int,float[]> land);

  public class MetaverseModel : IMetaverseModel
  {
    private Model _model;
    private IRenderingViewAdapter _adapter;
    private bool m_terrainCreated;

    public MetaverseModel(Model model)
    {
      _model = model;
      m_terrainCreated = false;
    }

    public void SetAdapter(IRenderingViewAdapter adapter)
    {
      _adapter = adapter;
    }

    #region IMetaverseModel Members


    public void ProcessIncomingAvatars(AddNewEntity sceneAddAvatar)
    {
      _model.ProcessIncomingAvatars(sceneAddAvatar);
    }

    public void ProcessIncomingPrim(AddNewEntity sceneAddPrim)
    {
      _model.ProcessIncomingPrim(sceneAddPrim);
    }

    public void ProcessLand(AddTerrainHandler handler)
    {
      if ((_model.LandMaps.Count > 255) && (!m_terrainCreated))
      {
        handler(_model.LandMaps);
        m_terrainCreated = true;
      }
    }

    #endregion
  }
}